<style>
    .layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {height:34px;line-height:34px;padding:0 8px;}
</style>
<body>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <div>
            <div class="layui-btn-group">
                <button class="layui-btn" id="btn-expand">全部展开</button>
                <button class="layui-btn layui-btn-normal" id="btn-fold">全部折叠</button>
            </div>
            <table id="munu-table" class="layui-table" lay-filter="munu-table"></table>
        </div>
    </div>
</div>
<!-- 操作列 -->
<script type="text/html" id="auth-state">
    {{#  if(d.type=='2'){ }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">选择下一步</a>
    {{# } }}

</script>
<script>
    layui.use(['table', 'axios','form','miniPage','treetable'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var treetable = layui.treetable;
        var axios = layui.axios;
        var miniPage = layui.miniPage;
        var form = layui.form;
        //加载渲染页面 treetable
        window.reload=function(){
            renderTable();
        }

        // 渲染表格
       var renderTable=function(){
           layer.load(2);
           treetable.render({
               treeColIndex: 1,
               treeSpid: -1,
               treeIdName: 'authorityId',
               treePidName: 'parentId',
               elem: '#munu-table',
               url: 'http://localhost:9999/dept/deptAll',
               page: false,
               treeDefaultClose:false,
               cols: [[
                   {type: 'numbers'},
                   {field: 'name', width: 250, title: '科室名称'},

                   {
                       field: 'type', width: 200, align: 'center', templet: function (d) {
                           if (d.type == 0) {
                               return '<span class="layui-badge layui-bg-gray">医院</span>';
                           }
                           if (d.type == 1) {
                               return '<span class="layui-badge layui-bg-blue">部门</span>';
                           } else {
                               return '<span class="layui-badge layui-btn-warm">科室</span>';
                           }
                       }, title: '类型'
                   },
                   {field: 'sort',width:120, title: '排序'},
                   {
                       field: 'status', width: 200, align: 'center', templet: function (d) {
                           if (d.status == 0) {
                               return '<span class="layui-badge layui-bg-gray">禁用</span>';
                           }
                           if (d.status == 1) {
                               return '<span class="layui-badge layui-bg-blue">正常</span>';
                           }
                       }, title: '状态'
                   },
                   {templet: '#auth-state', width: 200, align: 'center', title: '操作'}
               ]],
               done: function () {
                   layer.closeAll('loading');
               }
           });
       }

       //初次加载需要调用
        renderTable();

        $('#btn-expand').click(function () {
            treetable.expandAll('#munu-table');
        });

        $('#btn-fold').click(function () {
            treetable.foldAll('#munu-table');
        });



        //监听工具条
        table.on('tool(munu-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') {
                var content = miniPage.getHrefContent('page/other2/userlist.html');
                var openWH = miniPage.getOpenWidthHeight();

                var index = layer.open({
                    title: '查询医生列表',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                });
                localStorage.removeItem("deptId");
                localStorage.setItem("deptId",data.id)
                console.log(data.id)
                debugger
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });
    });
</script>
</body>
</html>